<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <!--引入Vue-->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div class="root">
  <h2>学校名称:{{ name }}</h2>
  <h2>学校地址:{{ address }}</h2>
  <h1>学生信息</h1>
  <button @click="addAttr">添加一个性别属性,默认值是男</button>
  <h2>学生姓名:{{ student.name }}</h2>
  <h2 v-if="student.gender">学生性别:{{ student.gender }}</h2>
  <h2>学生年龄:真实{{ student.age.rAge }},对外{{student.age.sAge}}</h2>
  <ul>
    <li v-for="f in student.friends">
      {{f.name}}--{{f.age}}
    </li>
  </ul>
</div>
</body>

<script type="text/javascript">
  const vm = new Vue({
    el: '.root',
    data: {
      name: '北大',
      address: '北京',
      student:{
        name: '刘宇诚',
        age:{
          rAge: 40,
          sAge: 29
        },
        friends: [
          {name: '张三',age: 35},
          {name: '李四',age: 33},
        ]
      }
    },
    methods: {
      addAttr(){
        // Vue.set只能用在响应式的对象上,不能直接用在vm上或者data上
        Vue.set(this.student,'gender','男')
      }
    }
  })
</script>
</html>
